package com.example.common.util;

import com.example.sys.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author alexzshl
 * @since 2022/1/28 22:10
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.context = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static Object getBean(String name) {
        return context.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return context.getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        return context.getBean(name, clazz);
    }

    //public static UserMapper getUserMapper() {
    //    return getBean(UserMapper.class);
    //}
    
    public static UserService getUserService() {
        return getBean(UserService.class);
    }
    
    //public static RoleService getRoleService() {
    //    return getBean(RoleService.class);
    //}

    //public static DictLangMapper getDictLangMapper() {
    //    return getBean(DictLangMapper.class);
    //}
    
    //public static DictLangService getDictLangService() {
    //    return getBean(DictLangService.class);
    //}

}
